/**
 * =====================================================================================
 *       @file  ngx_palloc.h
 *      @brief  
 *
 *  Detailed description starts here.
 *
 *   @internal
 *     Created  2012年05月08日 22时12分38秒 
 *    Revision  1.0.0.0
 *    Compiler  gcc/g++
 *
 *     @author  luis
 * =====================================================================================
 */

#ifndef H_NGX_PALLOC_H_INCLUDE_
#define H_NGX_PALLOC_H_INCLUDE_

#include <unistd.h>
#include "ngx_core.h"
#include "ngx_config.h"

#define NGX_POOL_ALIGNMENT      16

#define NGX_MAX_ALLOC_FROM_POOL (getpagesize() - 1)

typedef void (*ngx_pool_cleanup_pt)(void *data);

typedef struct ngx_pool_cleanup_s ngx_pool_cleanup_t;

struct ngx_pool_cleanup_s
{
    ngx_pool_cleanup_pt handler;
    void                *data;
    ngx_pool_cleanup_t  *next;
};

typedef struct ngx_pool_large_s ngx_pool_large_t;

struct ngx_pool_large_s
{
    ngx_pool_large_t    *next; 
    void                *alloc;
};

typedef struct
{
    u_char      *last;
    u_char      *end;
    ngx_pool_t  *next;
    ngx_uint_t  failed;
} ngx_pool_data_t;

struct ngx_pool_s
{
    ngx_pool_data_t     d;
    size_t              max;
    ngx_pool_t          *current;
    ngx_chain_t         *chain;
    ngx_pool_large_t    *large;
    ngx_pool_cleanup_t  *cleanup;
};

void *ngx_alloc(size_t size);
void *ngx_calloc(size_t size);

ngx_pool_t *ngx_create_pool(size_t size);
void ngx_destroy_pool(ngx_pool_t *pool);

void *ngx_palloc(ngx_pool_t *pool, size_t size);
void *ngx_pcalloc(ngx_pool_t *pool, size_t size);


#endif
